package cn.harmonyoslearn.navrouter.utils;

import cn.harmonyoslearn.navrouter.datas.NavName;
import cn.harmonyoslearn.navrouter.models.NavNamesModel;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Objects;

/**
 * 控制菜单是否显示
 */
public class UpdateUtil {
    public static void projectViewPopupMenuUpdate(@NotNull AnActionEvent e) {
        VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
        // 判断是否在ets目录下
        boolean isVisible = file != null && (file.getPath()).contains("main/ets");

        // 判断是否已经初始化，如果没有初始化则不显示创建页面选项
        boolean isInit = isInit(e);

        e.getPresentation().setVisible(isVisible && isInit);
        e.getPresentation().setEnabled(isVisible && isInit);
    }

    public static void initNavInfoActionUpdate(@NotNull AnActionEvent e) {
        boolean isInit = !isInit(e);

        e.getPresentation().setVisible(isInit);
        e.getPresentation().setEnabled(isInit);
    }

    private static boolean isInit(@NotNull AnActionEvent e) {
        String basePath = FileUtil.getBasePath(e);
        String navrouterInfoPath = basePath + "/navrouter-info.json";
        return FileUtil.isFile(navrouterInfoPath);
    }
}
